package com.kukudexin;

/**
 * @author: 酷酷的鑫
 * @Date: 2021/12/8 18:02
 * @description:
 */
public class Test18 {
    public static void main(String[] args) {
        GenericFather<Integer> f = new GenericFather<>(Integer.valueOf(123));
        //创建子类对象
        GenericSon<Integer> s1 = new GenericSon<>(Integer.valueOf(456));
        GenericSon<String> s2 = new GenericSon<>("hello");

        //在判断运行时类对象时,可以使用通配 符
        if ( s1 instanceof GenericSon<?> ){
            System.out.println("s1  是 GenericSon类的对象");
        }

        if ( s1 instanceof GenericFather<?> ){
            System.out.println("s1 是GenericFather类的对象");
        }

        if (f instanceof  GenericSon<?> ){      //false
            System.out.println("f 是 GenericSon类的对象");
        }

        System.out.println( s1.getClass() == s2.getClass());
    }
    //定义泛型类作为父类
    static class GenericFather<T>{
        private T val;

        public GenericFather(T val) {
            this.val = val;
        }

        public T getVal() {
            return val;
        }

        public void setVal(T val) {
            this.val = val;
        }
    }
    //定义泛型子类
    static class GenericSon<T> extends GenericFather<T>{
        public GenericSon(T val) {
            super(val);
        }
    }
}
